using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VPJKOPF
    {
        public DataRow Convert2PJKOPF(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryPJKOPF(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["PKOMANDANT"] = " ".PadRight(2 ); 
         dwReturn["PKOPROJNR"] = " ".PadRight(5 ); 
         dwReturn["PKOSTATUS"] = " ".PadRight(1 ); 
         dwReturn["PKOVB"] = " ".PadRight(3 ); 
         dwReturn["PKOVG"] = " ".PadRight(3 ); 
         dwReturn["PKOBEZ"] = " ".PadRight(50 ); 
         dwReturn["PKOKURZBEZ"] = " ".PadRight(10 ); 
         dwReturn["PKOGUELTAB"] = " ".PadRight(0 ); 
         dwReturn["PKOGUELTBIS"] = " ".PadRight(0 ); 
         dwReturn["PKOPROJLEITER"] = " ".PadRight(8 ); 
         dwReturn["PKOBUDGET"] = " ".PadRight(0 ); 
         dwReturn["PKOKOSTEN"] = " ".PadRight(0 ); 
         dwReturn["PKOUMSPLAN"] = " ".PadRight(0 ); 
         dwReturn["PKOUMSIST"] = " ".PadRight(0 ); 
         dwReturn["PKOANZKUNDEN"] = " ".PadRight(0 ); 
         dwReturn["PKOANZTAET"] = " ".PadRight(0 ); 
         dwReturn["PKOANZTAETUEBW"] = " ".PadRight(0 ); 
         dwReturn["PKOANZTAETERL"] = " ".PadRight(0 ); 
         dwReturn["PKONEUBEN"] = " ".PadRight(8 ); 
         dwReturn["PKONEUDAT"] = " ".PadRight(0 ); 
         dwReturn["PKOAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["PKOAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["PKOAENDZL"] = " ".PadRight(0 ); 
         dwReturn["PKOSELEKTION"] = " ".PadRight(400 ); 
         dwReturn["PKOFILLER"] = " ".PadRight(20 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapPJKOPF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SavePJKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryPJKOPF(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapPJKOPF(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertPJKOPF(dwLocal, ITXDBVERSION);
            }
            UpdatePJKOPF(dwLocal);
        }
        public void InsertPJKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO PJKOPF(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryPJKOPF(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM PJKOPF WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM PJKOPF  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "PJKOPF";
            Return = Result;
            return Return;
        }
        public void DeletePJKOPF(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM PJKOPF   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdatePJKOPF(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE PJKOPF SET "
                    +"PKOMANDANT= :PKOMANDANT,"
                    +"PKOPROJNR= :PKOPROJNR,"
                    +"PKOSTATUS= :PKOSTATUS,"
                    +"PKOVB= :PKOVB,"
                    +"PKOVG= :PKOVG,"
                    +"PKOBEZ= :PKOBEZ,"
                    +"PKOKURZBEZ= :PKOKURZBEZ,"
                    +"PKOGUELTAB= :PKOGUELTAB,"
                    +"PKOGUELTBIS= :PKOGUELTBIS,"
                    +"PKOPROJLEITER= :PKOPROJLEITER,"
                    +"PKOBUDGET= :PKOBUDGET,"
                    +"PKOKOSTEN= :PKOKOSTEN,"
                    +"PKOUMSPLAN= :PKOUMSPLAN,"
                    +"PKOUMSIST= :PKOUMSIST,"
                    +"PKOANZKUNDEN= :PKOANZKUNDEN,"
                    +"PKOANZTAET= :PKOANZTAET,"
                    +"PKOANZTAETUEBW= :PKOANZTAETUEBW,"
                    +"PKOANZTAETERL= :PKOANZTAETERL,"
                    +"PKONEUBEN= :PKONEUBEN,"
                    +"PKONEUDAT= :PKONEUDAT,"
                    +"PKOAENDBEN= :PKOAENDBEN,"
                    +"PKOAENDDAT= :PKOAENDDAT,"
                    +"PKOAENDZL= :PKOAENDZL,"
                    +"PKOSELEKTION= :PKOSELEKTION,"
                    +"PKOFILLER= :PKOFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("PKOMANDANT", OracleType.NVarChar).Value = dwData["PKOMANDANT"].ToString(); 
          or1.Parameters.Add("PKOPROJNR", OracleType.NVarChar).Value = dwData["PKOPROJNR"].ToString(); 
          or1.Parameters.Add("PKOSTATUS", OracleType.NVarChar).Value = dwData["PKOSTATUS"].ToString(); 
          or1.Parameters.Add("PKOVB", OracleType.NVarChar).Value = dwData["PKOVB"].ToString(); 
          or1.Parameters.Add("PKOVG", OracleType.NVarChar).Value = dwData["PKOVG"].ToString(); 
          or1.Parameters.Add("PKOBEZ", OracleType.NVarChar).Value = dwData["PKOBEZ"].ToString(); 
          or1.Parameters.Add("PKOKURZBEZ", OracleType.NVarChar).Value = dwData["PKOKURZBEZ"].ToString(); 
          or1.Parameters.Add("PKOGUELTAB", OracleType.NVarChar).Value = dwData["PKOGUELTAB"].ToString(); 
          or1.Parameters.Add("PKOGUELTBIS", OracleType.NVarChar).Value = dwData["PKOGUELTBIS"].ToString(); 
          or1.Parameters.Add("PKOPROJLEITER", OracleType.NVarChar).Value = dwData["PKOPROJLEITER"].ToString(); 
          or1.Parameters.Add("PKOBUDGET", OracleType.NVarChar).Value = dwData["PKOBUDGET"].ToString(); 
          or1.Parameters.Add("PKOKOSTEN", OracleType.NVarChar).Value = dwData["PKOKOSTEN"].ToString(); 
          or1.Parameters.Add("PKOUMSPLAN", OracleType.NVarChar).Value = dwData["PKOUMSPLAN"].ToString(); 
          or1.Parameters.Add("PKOUMSIST", OracleType.NVarChar).Value = dwData["PKOUMSIST"].ToString(); 
          or1.Parameters.Add("PKOANZKUNDEN", OracleType.NVarChar).Value = dwData["PKOANZKUNDEN"].ToString(); 
          or1.Parameters.Add("PKOANZTAET", OracleType.NVarChar).Value = dwData["PKOANZTAET"].ToString(); 
          or1.Parameters.Add("PKOANZTAETUEBW", OracleType.NVarChar).Value = dwData["PKOANZTAETUEBW"].ToString(); 
          or1.Parameters.Add("PKOANZTAETERL", OracleType.NVarChar).Value = dwData["PKOANZTAETERL"].ToString(); 
          or1.Parameters.Add("PKONEUBEN", OracleType.NVarChar).Value = dwData["PKONEUBEN"].ToString(); 
          or1.Parameters.Add("PKONEUDAT", OracleType.NVarChar).Value = dwData["PKONEUDAT"].ToString(); 
          or1.Parameters.Add("PKOAENDBEN", OracleType.NVarChar).Value = dwData["PKOAENDBEN"].ToString(); 
          or1.Parameters.Add("PKOAENDDAT", OracleType.NVarChar).Value = dwData["PKOAENDDAT"].ToString(); 
          or1.Parameters.Add("PKOAENDZL", OracleType.NVarChar).Value = dwData["PKOAENDZL"].ToString(); 
          or1.Parameters.Add("PKOSELEKTION", OracleType.NVarChar).Value = dwData["PKOSELEKTION"].ToString(); 
          or1.Parameters.Add("PKOFILLER", OracleType.NVarChar).Value = dwData["PKOFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
